﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports GenDotNet.TemplateSupport.Strings

Public Class GenericInfo
   Inherits BaseInfo

   Private mConstraints As New List(Of TypeInfo)

   Public Sub New(ByVal name As String)
      MyBase.New(name, TemplateSupport.Scope.Unknown)
   End Sub

   Public ReadOnly Property Constraints() As List(Of TypeInfo)
      Get
         Return mConstraints
      End Get
   End Property

End Class

Public Class GenericInfoCollection
   Inherits List(Of GenericInfo)

   Public Overloads Sub Add(ByVal className As String)
      Me.Add(New GenericInfo(className))
   End Sub

End Class

Namespace VB

   Public Module GenericInfoExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal list As GenericInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Return "(Of " & (From item In list Select item.Name).ConcatenateWithComma & ")"
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal generic As GenericInfo) As String
         If generic Is Nothing Then
            Return String.Empty
         End If
         Dim ret = "(Of " & generic.Name & ")"
         Return ret
      End Function

   End Module

End Namespace

Namespace CSharp

   Public Module GenericInfoExtensions
      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal list As GenericInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Return "< " & (From item In list Select item.Name).ConcatenateWithComma & " >"
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal generic As GenericInfo) As String
         If generic Is Nothing Then
            Return String.Empty
         End If
         Dim ret = "<" & generic.Name & ">"
         Return ret
      End Function

   End Module

End Namespace

